<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>promise-api</title>
</head>

<body>
    <script type="text/javascript">
        /*
          Promise常用API-实例方法
        */
        function foo() {
            return new Promise(function (resolve, reject) {
                // 异步执行的方法
                setTimeout(function () {
                    //    resolve('正确！');
                    reject('error');
                }, 1000);
            });
        }

        foo()
            .then(function (data) {
                console.log(data);
            })
            .catch(function (data) {
                console.log('catch....');
                console.log(data);
            })
            .finally(function () {
                console.log('finally');
            });
    </script>
</body>

</html>